import {getKeyData} from './utils.js'
export default (listData,process,dataType)=>{
	var sourceType = 'array'
	if(Object.prototype.toString.call(listData) === '[object Object]'){
		sourceType = 'object'
		listData = [].concat(listData)
	}
	if(!process){
		process = []
	}
	listData.forEach(data=>{
		process.forEach(cess=>{
			var realField = cess.field
			if(dataType === 'list'){
				var idx = realField.indexOf('Array%krt_')
				realField = realField.substr(idx+10)
			}
			var targetObj = getKeyData(realField,data,false,sourceType === 'object');
			var targetField = realField.split('%krt_').slice(-1).join('');
			var targetVal = targetObj[targetField] + '';
			if(cess.type === 'map'){
				cess.table.some(key=>{
					if(key.key === targetVal){
						targetObj[targetField] = key.val
						return true
					}
				})
			}
		})
	})
	if(sourceType === 'object'){
		return listData[0]
	}else{
		return listData
	}
}